/*
 * Bag.h
 *
 *  Created on: 2013. 9. 9.
 *      Author: jjaehuny
 */

#ifndef PROJECTZ_NLOGIC_BAG_H_
#define PROJECTZ_NLOGIC_BAG_H_

#include <vector>
#include <inttypes.h>

#include "../Enum.h"
#include "Item.h"

namespace ProjectZ {
class User;
} /*ProjectZ*/

namespace ProjectZ {
namespace NLogic {

class Item;

class Bag {
public:
	typedef std::vector<Item *> ITEMVECTOR;

public:
	Bag() :
			_user(0), _bLoad(false), _bDecreaseBattlepetStamina(false), _itemCount(0), _eBagType(0), _maxSlotCount(0) {
	}
	Bag(User * pUser, int eBagType);
	virtual ~Bag();

	void Initialize();
	void Finalize();

	bool AddItem(Item * pItem);
	Item * GetItem(uint64_t ItemSeq);
	Item * PopItem(uint64_t ItemSeq);
	//Item * GetItemFromIndex(int index);

	bool IsBagFull();
	bool IsExistItem(uint64_t ItemSeq);
	bool IsExistSameItem(const Item::Data & data);

	int RemainBagSlotCount();

	//bool ChangeItemSlot(int srcIndex, int dstIndex);
	//int FindEmptyItemSlot() const;
	int HasItemCount();
	int GetMaxSlotCount() { return _maxSlotCount; }
	void DecreaseBattlePetStamina();

	bool ItemLoadFromDatabase();
	bool	ItemLoadFromDatabase_Asyn();
	bool	ItemLoadFromDatabase_Asyn_Result();

	Item * GetIdentifyScroll();
	Item * AddItemWithData(Item::Data& data, bool & bBagFull, bool bOpenNone = false);

	ITEMVECTOR & GetItemVector() {
		return _clsItemVector;
	}
	int GetBagType() const {
		return _eBagType;
	}

	void SetLoadComplete() { _bLoad = true; }
	bool IsLoad() const {
		return _bLoad;
	}
	bool IsDecreaseBattlePetStamina() const {
		return _bDecreaseBattlepetStamina;
	}



private:
	Item * GetStackItem(const Item::Data & data);

private:
	User * _user;
	ITEMVECTOR _clsItemVector;

	bool _bLoad;
	bool _bDecreaseBattlepetStamina;
	int _itemCount;

	int _eBagType;
	int _maxSlotCount;
};

} /*NLogic*/
} /* namespace ProjectZ */

#endif /* PROJECTZ_NLOGIC_BAG_H_ */
